package com.gitee.fanx.rpc.test.client;

import com.gitee.fanx.rpc.client.EnableRpcClients;
import com.gitee.fanx.rpc.client.RpcClientCustomizer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.JdkClientHttpRequestFactory;

/**
 * rpc客户端解析异常响应
 *
 * @author fanhang
 */
@EnableRpcClients
@EnableDiscoveryClient
@SpringBootApplication
public class ClientBoot {

	public static void main(String[] args) {
		SpringApplication.run(ClientBoot.class);
	}

	/**
	 * 负载均衡, 配置名称服务
	 */
	@Bean
	public RpcClientCustomizer rpcClientCustomizer(LoadBalancerClient loadBalancer) {
		 LoadBalancerInterceptor interceptor = new LoadBalancerInterceptor(loadBalancer);
		return restTemplate -> {
			restTemplate.getInterceptors().add(interceptor);
			restTemplate.setRequestFactory(new JdkClientHttpRequestFactory());
		};
	}

}
